<script setup>
import { Search } from '@element-plus/icons-vue'
import axios from 'axios'
import { onMounted, ref } from 'vue'
import router from '../router/router'
import { useStore } from 'vuex'
const store = useStore()

const uid = ref(store.state.userStore.userInfo.data.id)
const tableData = ref([])
const Detail = (row) => {
  router.push({
    name: '博客详情',
    query: { id: row.id }
  })
}
const handleDelete = (i, item) => {
  tableData.value.splice(i, 1)
  router.push({
    name: '回收站',
    query: { id: item.id }
  })
  console.log(tableData)
}

onMounted(() => {
  axios.get('/api/mycontroller1/mymethod/' + uid.value).then((res) => {
    tableData.value = res.data
    store.dispatch('articleStore/saveArticleInfoAction', res)
    console.log(tableData.value)
  })
})
</script>

<template>

<div class="head">
  <div class="input">
      <el-form-item >
        <el-input type="text" prefix-icon="el-icon-search" placeholder="通过标题搜索博客"></el-input>
      </el-form-item>
  </div>
  <div class="searchButton">
    <el-button type="primary" :icon="Search">Search</el-button>
  </div>
</div>

<el-table :data="tableData"  :border="false"
      :header-cell-style="{'text-align':'left'}"
      :cell-style="{'text-align':'left'}"
      @cell-click="goclick">
    <el-table-column prop="title" label="标题" width="400" >
      <template v-slot="scope">
          <div @click="Detail(scope.row)" style=" color: #87CEFA;;cursor: pointer;">
            {{scope.row.title}}

          </div>

        </template>

    </el-table-column>
    <el-table-column prop="edittime" label="最近编辑时间" width="330" />
    <el-table-column prop="uid" label="作者"  width="250" />
    <el-table-column align="right">
      <template #default="scope">
  <el-popconfirm
        confirm-button-text="是的"
         @confirm="handleDelete(scope.$index,scope.row)"
        cancel-button-text="取消"
        :icon="InfoFilled"
        icon-color="red"
          title="确定删除吗?">
 <template #reference>
      <el-button type="danger" size="small">删除
      </el-button>
  </template>
      </el-popconfirm>
      </template>
    </el-table-column>
  </el-table>
</template>

<style scoped>
.head{
  display: flex;
  justify-content: space-between;
}
.input{
  display: flex;
  width: 400px;
  margin-right: -280px;
}
.searchButton{
  display: flex;
  margin-left: 100px;
}

</style>
